﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess.DataObject;

namespace DataAccess.BusinessObject
{
    public class BFAQ:Common.CDBase
    {

        /// <summary>
        /// Add faq
        /// </summary>
        /// <param name="_OFAQ"></param>
        /// <returns></returns>
        public bool Add(OFAQ _OFAQ)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@Question",SqlDbType.NVarChar),
                                      new SqlParameter("@Answer",SqlDbType.NVarChar),
                                      new SqlParameter("@Sender",SqlDbType.NVarChar),
                                      new SqlParameter("@Replyer",SqlDbType.NVarChar),
                                      new SqlParameter("@SendDate",SqlDbType.DateTime),
                                      new SqlParameter("@ReplyDate",SqlDbType.DateTime),
                                      new SqlParameter("@Status",SqlDbType.VarChar),
                                      new SqlParameter("@CatID",SqlDbType.Int)};
            sqlParam[0].Value = _OFAQ.Question;
            sqlParam[1].Value = _OFAQ.Answer;
            sqlParam[2].Value = _OFAQ.Sender;
            sqlParam[3].Value = _OFAQ.Replyer;
            sqlParam[4].Value = _OFAQ.SendDate;
            sqlParam[5].Value = _OFAQ.ReplyDate;
            sqlParam[6].Value = _OFAQ.Status;
            sqlParam[7].Value = _OFAQ.CatID;
            return RunProcedure("sp_tblFAQ_add", sqlParam);
        }
        public bool Update(OFAQ _OFAQ)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@FAQID",SqlDbType.Int),
                                        new SqlParameter("@Question",SqlDbType.NVarChar),
                                        new SqlParameter("@Answer",SqlDbType.NVarChar),
                                        new SqlParameter("@Sender",SqlDbType.NVarChar),
                                        new SqlParameter("@Replyer",SqlDbType.NVarChar),
                                        new SqlParameter("@SendDate",SqlDbType.DateTime),
                                        new SqlParameter("@ReplyDate",SqlDbType.DateTime),
                                        new SqlParameter("@Status",SqlDbType.VarChar),
                                        new SqlParameter("@CatID",SqlDbType.Int)};
            sqlParam[0].Value = _OFAQ.FAQID;
            sqlParam[1].Value = _OFAQ.Question;
            sqlParam[2].Value = _OFAQ.Answer;
            sqlParam[3].Value = _OFAQ.Sender;
            sqlParam[4].Value = _OFAQ.Replyer;
            sqlParam[5].Value = _OFAQ.SendDate;
            sqlParam[6].Value = _OFAQ.ReplyDate;
            sqlParam[7].Value = _OFAQ.Status;
            sqlParam[8].Value = _OFAQ.CatID;
            return RunProcedure("sp_tblFAQ_update", sqlParam);
        }
        public bool Delete(int FAQID)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@FAQID",SqlDbType.Int)};
            sqlParam[0].Value = FAQID;
            return RunProcedure("sp_tblFAQ_delete", sqlParam);
        }
        public IList<OFAQ> Get(int FAQID,string Status,int CatID,string OrderBy,string Order,int PageIndex,int PageSize)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@FAQID",SqlDbType.Int),
                                      new SqlParameter("@Status",SqlDbType.VarChar),
                                      new SqlParameter("@CatID",SqlDbType.Int),
                                      new SqlParameter("@OrderBy",SqlDbType.VarChar),
                                      new SqlParameter("@Order",SqlDbType.VarChar),
                                      new SqlParameter("@PageIndex",SqlDbType.Int),
                                      new SqlParameter("@PageSize",SqlDbType.Int)};
            sqlParam[0].Value = FAQID;
            sqlParam[1].Value = Status;
            sqlParam[2].Value = CatID;
            sqlParam[3].Value = OrderBy;
            sqlParam[4].Value = Order;
            sqlParam[5].Value = PageIndex;
            sqlParam[6].Value = PageSize;
            return Common.Common.ConvertTo<OFAQ>(RunProcedureGet("sp_tblFAQ_get", sqlParam));
        }        
    }

}
